package com.lysj.bhp.wallet.service;

import com.lysj.bhp.wallet.base.WalletContent;
import com.lysj.bhp.wallet.domain.BuWallet;
import io.bumo.crypto.Keypair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
@Service
public class BuWalletService extends WalletContent {
    private static Logger logger = LoggerFactory.getLogger(BuWalletService.class);

    public  BuWallet createBuWallet(Long userId) {
        Keypair keypair = Keypair.generator();
        BuWallet buWallet = new BuWallet();
        buWallet.setUserId(userId);
        buWallet.setAddress(keypair.getAddress());
        buWallet.setPrivKey(keypair.getPrivateKey());
        buWallet.setPublicKey(keypair.getPublicKey());

        buWallet.setBalance(BigDecimal.ZERO);
        buWallet.setFreezeBalance(BigDecimal.ZERO);
        buWallet.setAvailBalance(BigDecimal.ZERO);
        buWallet.setBookKeepBalance(BigDecimal.ZERO);
        //------------增加钱包的抵押冻结资产----------------
        buWallet.setPledgeFreezeBalance(BigDecimal.ZERO);
        buWalletRepository.save(buWallet);
        logger.info("创建了一个新的钱包:" + buWallet);
        return buWallet;
    }
}
